<?php 
	include("includes/connect_db.php"); 

	$aksi = $_GET['aksi'];
	$filter = $_POST['filter'];

	$sql_lihat_host_akademik = "SELECT * FROM tb_host WHERE db = 'db_seo_akademik'";
	$query_lihat_host_akademik = mysql_query($sql_lihat_host_akademik);
	$lihat_host_akademik = mysql_fetch_array($query_lihat_host_akademik);

	$konMhs = mysqli_connect($lihat_host_akademik['host'], $lihat_host_akademik['username'], $lihat_host_akademik['password']) or die("Connection Error: " . mysqli_error());
	mysqli_select_db($konMhs, $lihat_host_akademik['db']) or die("Error conecting to db.");

	$sql_lihat_host_pegawai = "SELECT * FROM tb_host WHERE db = 'db_seo_kepegawaian'";
	$query_lihat_host_pegawai = mysql_query($sql_lihat_host_pegawai);
	$lihat_host_pegawai = mysql_fetch_array($query_lihat_host_pegawai);

	$konPeg = mysqli_connect($lihat_host_pegawai['host'], $lihat_host_pegawai['username'], $lihat_host_pegawai['password']) or die("Connection Error: " . mysqli_error());
	mysqli_select_db($konPeg, $lihat_host_pegawai['db']) or die("Error conecting to db.");

	switch ($aksi) {
		case '1':
			switch ($filter) {
				case 'status':
					echo "<div class='filterPlacer'>";
						echo "<span style='margin-left: 10px;'>";
							echo "Status";
						echo "</span>";
						echo "<span style='margin-left: 10px;'>";
							echo "<input type='hidden' class='namaFilter' value='status'>";
							echo "<select class='filter status' style='width: 60%;'>";
								echo "<option value='1'>";
									echo "Aktif";
								echo "</option>";
								echo "<option value='2'>";
									echo "Cuti";
								echo "</option>";
								echo "<option value='3'>";
									echo "Alumni";
								echo "</option>";
								echo "<option value='4'>";
									echo "Tidak Aktif";
								echo "</option>";
							echo "</select>";
						echo "</span>";
						echo "<span>";
							echo "<button class='btn btn-danger removeFilter pull-right'>";
								echo "<i class='icon-remove'></i>";
							echo "</button>";
						echo "</span>";
					echo "</div>";
					break;
				
				case 'angkatan':
					echo "<div class='filterPlacer'>";
						echo "<span style='margin-left: 10px;'>";
							echo "Angkatan";
						echo "</span>";
						echo "<span style='margin-left: 10px;'>";
							echo "<input type='hidden' class='namaFilter' value='angkatan'>";
							echo "<select class='filter angkatan' style='width: 60%;'>";
							$sql_ambil_data = "SELECT * FROM tb_angkatan";
							$query_ambil_data = mysqli_multi_query($konMhs, $sql_ambil_data);
							$ambil_data = mysqli_store_result($konMhs);
							while ($data = mysqli_fetch_array($ambil_data)) {
								echo "<option value='$data[id_angkatan]'>";
									echo $data['angkatan'];
								echo "</option>";
							}
							echo "</select>";
						echo "</span>";
						echo "<span>";
							echo "<button class='btn btn-danger removeFilter pull-right'>";
								echo "<i class='icon-remove'></i>";
							echo "</button>";
						echo "</span>";
					echo "</div>";
					break;
				
				case 'mataKuliah':
					echo "<div class='filterPlacer'>";
						echo "<span style='margin-left: 10px;'>";
							echo "Mata Kuliah";
						echo "</span>";
						echo "<span style='margin-left: 10px;'>";
							echo "<input type='hidden' class='namaFilter' value='mk'>";
							echo "<select class='filter mk' style='width: 60%;'>";
									$sql = "SELECT 
												tb_mk.id_mk AS id_mk, 
												tb_mk_penawaran.id_penawaran AS id_penawaran, 
												tb_periode.status AS STATUS, tb_mk.nama AS nama, 
												tb_mk_penawaran.kelas AS kelas
											FROM
												db_seo_akademik.tb_mk_penawaran
												INNER JOIN 
													db_seo_akademik.tb_mk
												ON 
													(tb_mk_penawaran.id_mk = tb_mk.id_mk)
												INNER JOIN 
													db_seo_akademik.tb_periode
												ON 
													(tb_mk_penawaran.id_periode = tb_periode.id_periode)
											WHERE
												STATUS = '1'
											ORDER BY
												nama;";

									$query = mysqli_multi_query($konMhs, $sql);
									$data = mysqli_store_result($konMhs);
									while ($result = mysqli_fetch_array($data)) {
										echo "<option value='$result[id_penawaran]'>";
											echo $result['nama']." ".$result['kelas'];
										echo "</option>";
									}
							echo "</select>";
						echo "</span>";
						echo "<span>";
							echo "<button class='btn btn-danger removeFilter pull-right'>";
								echo "<i class='icon-remove'></i>";
							echo "</button>";
						echo "</span>";
					echo "</div>";
					break;
				
				case 'pa':
					echo "<div class='filterPlacer'>";
						echo "<span style='margin-left: 10px;'>";
							echo "P.A.";
						echo "</span>";
						echo "<span style='margin-left: 10px;'>";
							echo "<input type='hidden' class='namaFilter' value='pa'>";
							echo "<select class='filter pa' style='width: 60%;'>";
									$sql = "SELECT * FROM tb_master_pegawai WHERE tanda = '0'";
									$query = mysqli_multi_query($konPeg, $sql);
									$data = mysqli_store_result($konPeg);
									while ($result = mysqli_fetch_array($data)) {
										echo "<option value='$result[id_master_pegawai]'>";
											echo $result['nama_lengkap'];
										echo "</option>";
									}
							echo "</select>";
						echo "</span>";
						echo "<span>";
							echo "<button class='btn btn-danger removeFilter pull-right'>";
								echo "<i class='icon-remove'></i>";
							echo "</button>";
						echo "</span>";
					echo "</div>";
					break;
				
				case 'agama':
					echo "<div class='filterPlacer'>";
						echo "<span style='margin-left: 10px;'>";
							echo "Agama";
						echo "</span>";
						echo "<span style='margin-left: 10px;'>";
							echo "<input type='hidden' class='namaFilter' value='agama'>";
							echo "<select class='filter agama'style='width: 60%;'>";
									$sql_ambil_data = "SELECT * FROM tb_master_agama";
									$query_ambil_data = mysqli_multi_query($konMhs, $sql_ambil_data);
									$ambil_data = mysqli_store_result($konMhs);
									while ($data = mysqli_fetch_array($ambil_data)) {
										echo "<option value='$data[id_master_agama]'>";
											echo $data['agama'];
										echo "</option>";
									}
							echo "</select>";
						echo "</span>";
						echo "<span>";
							echo "<button class='btn btn-danger removeFilter pull-right'>";
								echo "<i class='icon-remove'></i>";
							echo "</button>";
						echo "</span>";
					echo "</div>";
					break;
				
				default:
					# code...
					break;
			}
			break;
		case '2':
			switch ($filter) {
				case 'entitas':
					echo "<div class='filterPlacer'>";
						echo "<span style='margin-left: 10px;'>";
							echo "Entitas";
						echo "</span>";
						echo "<span style='margin-left: 10px;'>";
							echo "<input type='hidden' class='namaFilter' value='entitas'>";
							echo "<select class='filter entitas' style='width: 60%;'>";
								echo "<option value='0'>";
									echo "Dosen";
								echo "</option>";
								echo "<option value='1'>";
									echo "Pegawai";
								echo "</option>";
							echo "</select>";
						echo "</span>";
						echo "<span>";
							echo "<button class='btn btn-danger removeFilter pull-right'>";
								echo "<i class='icon-remove'></i>";
							echo "</button>";
						echo "</span>";
					echo "</div>";
					break;
				
				case 'status':
					echo "<div class='filterPlacer'>";
						echo "<span style='margin-left: 10px;'>";
							echo "Status";
						echo "</span>";
						echo "<span style='margin-left: 10px;'>";
							echo "<input type='hidden' class='namaFilter' value='status'>";
							echo "<select class='filter status' style='width: 60%;'>";
									$sql_ambil_data = "SELECT * FROM tb_master_jenis_pegawai";
									$query_ambil_data = mysqli_multi_query($konPeg, $sql_ambil_data);
									$ambil_data = mysqli_store_result($konPeg);
									while ($data = mysqli_fetch_array($ambil_data)) {
										echo "<option value='$data[id_master_jenis_pegawai]'>";
											echo $data['jenis_pegawai'];
										echo "</option>";
									}
							echo "</select>";
						echo "</span>";
						echo "<span>";
							echo "<button class='btn btn-danger removeFilter pull-right'>";
								echo "<i class='icon-remove'></i>";
							echo "</button>";
						echo "</span>";
					echo "</div>";
					break;
				
				case 'agama':
					echo "<div class='filterPlacer'>";
						echo "<span style='margin-left: 10px;'>";
							echo "Agama";
						echo "</span>";
						echo "<span style='margin-left: 10px;'>";
							echo "<input type='hidden' class='namaFilter' value='agama'>";
							echo "<select class='filter agama'style='width: 60%;'>";
									$sql_ambil_data = "SELECT * FROM tb_master_agama";
									$query_ambil_data = mysqli_multi_query($konMhs, $sql_ambil_data);
									$ambil_data = mysqli_store_result($konMhs);
									while ($data = mysqli_fetch_array($ambil_data)) {
										echo "<option value='$data[id_master_agama]'>";
											echo $data['agama'];
										echo "</option>";
									}
							echo "</select>";
						echo "</span>";
						echo "<span>";
							echo "<button class='btn btn-danger removeFilter pull-right'>";
								echo "<i class='icon-remove'></i>";
							echo "</button>";
						echo "</span>";
					echo "</div>";
					break;
			}
			break;

		default:
			# code...
			break;
	}
?>